package de.zefania.api.impl;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;


public class DictionaryReader {
	private Document bibleDoc;
	private Logger logger = Logger.getLogger(DictionaryReader.class);

	public DictionaryReader(final File file) throws SAXException, IOException, ParserConfigurationException {
		BasicConfigurator.configure();
		logger.setLevel(Level.DEBUG);
		bibleDoc = XmlTools.getDocumentFromFile(file);
	}
	
	public final HashMap<String,String> getInformation() {
		NodeList nodes = bibleDoc.getElementsByTagName("INFORMATION").item(0).getChildNodes();
		HashMap<String,String> information = new HashMap<String,String>();
		for (int i=0;i<nodes.getLength();i++) {	
			if (nodes.item(i).getNodeType()==Node.ELEMENT_NODE) {
				information.put(
					nodes.item(i).getNodeName(), 
					nodes.item(i).getTextContent());
			}
		}
		return information;		
	}
	
	
	
}
